package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;

import com.itheima.service.CheckGroupService;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 检查项管理
 */

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {
    @Reference//查找服务
    private CheckGroupService checkGroupService;

    //新增检查项
    @RequestMapping("/add")
    public Result add(@RequestBody @Valid CheckGroup checkGroup, Integer[] checkitemIds) {
//        if(errors.hasErrors()){
//            for (FieldError error : errors.getFieldErrors()) {
//                System.out.println(error.getDefaultMessage());
//                return new Result(false, error.getDefaultMessage());
//            }
//        }
        return checkGroupService.add(checkGroup, checkitemIds);
    }

    @RequestMapping("/findpage")

    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return checkGroupService.findPage(queryPageBean);
    }
    @RequestMapping("/findById")
    public Result findById(int id) {
        return checkGroupService.findById(id);
    }

    @RequestMapping("/edit")
    public Result edit(@RequestBody  @Valid CheckGroup checkGroup,Integer[] checkitemIds){

        return checkGroupService.edit(checkGroup, checkitemIds);
    }

    @RequestMapping("/delete")
    public Result delete( Integer id) {
        return checkGroupService.deleteById(id);
    }

    @RequestMapping("/findAll")
    public Result findAll() {
        return checkGroupService.finAll();
    }
}
